package com.example.shopping_mall.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.shopping_mall.R;
import com.example.shopping_mall.bean.UiKillDetailBean;
import com.example.shopping_mall.bean.UiRecommendBean;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

//秒杀详情时间
public class KillDetailAdapter extends RecyclerView.Adapter<KillDetailAdapter.KillDetailHolder>{

    private Context context;
    private List<UiKillDetailBean> detailBeans;
    private onKillDetailClickListener detailClickListener;
    private int mposition=0;

    public void setMposition(int mposition) {
        this.mposition = mposition;
    }

    public KillDetailAdapter(Context context) {
        this.context = context;
    }

    public void setDetailBeans(List<UiKillDetailBean> detailBeans) {
        this.detailBeans = detailBeans;
    }

    public void setDetailClickListener(onKillDetailClickListener detailClickListener) {
        this.detailClickListener = detailClickListener;
    }

    @NonNull
    @Override
    public KillDetailHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new KillDetailHolder(LayoutInflater.from(context).inflate(R.layout.kill_detail_item_list,null));
    }

    @Override
    public void onBindViewHolder(@NonNull KillDetailHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.killTime.setText(detailBeans.get(position).getKillTime());
        holder.killBuy.setText(detailBeans.get(position).getKillBuy());
        //holder.killTitle.setText(detailBeans.get(position).getKillTitle());

        if(mposition==position){
            holder.layout.setBackgroundColor(Color.parseColor("#fb9953"));
        }else {
            holder.layout.setBackgroundColor(Color.parseColor("#5f5f5f"));
        }

        if (detailClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    detailClickListener.onKillDetailClick(position);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return null==detailBeans?0:detailBeans.size();
    }

    class KillDetailHolder extends RecyclerView.ViewHolder{

        RelativeLayout layout;
        TextView killTime;
        TextView killBuy;
        //TextView killTitle;

        public KillDetailHolder(@NonNull View itemView) {
            super(itemView);

            layout=itemView.findViewById(R.id.kill_detail_layout);
            killTime=itemView.findViewById(R.id.kill_detail_time);
            killBuy=itemView.findViewById(R.id.kill_detail_buy);
            //killTitle=itemView.findViewById(R.id.kill_detail_title);
        }
    }

    public interface onKillDetailClickListener{
        void onKillDetailClick(int position);
    }
}
